﻿namespace TfsCloudDeploy.Workflow.Core
{
    using System;
    using System.ComponentModel;
    using TfsCloudDeploy.Workflow.Core.Activities;

    /// <summary>
    /// Represents the properties of an override transform.
    /// </summary>
    [Serializable, TypeConverter(typeof(OverrideTransformConverter))]
    public class OverrideTransform
    {
        public OverrideTransform()
        {

        }

        public OverrideTransform(string localPathToWebConfigUnderSourceRoot, string localFileNameToReplaceWithTransformFile)
            : this()
        {
            this.LocalPathToWebConfigUnderSourceRoot = localPathToWebConfigUnderSourceRoot;
            this.LocalFileNameToReplaceWithTransformFile = localFileNameToReplaceWithTransformFile;
        }

        /// <summary>
        /// The path to the web.config file starting from the source folder's root.
        /// </summary>
        [Browsable(true), RefreshProperties(RefreshProperties.All), SRDisplayName(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.LocalPathToWebConfigUnderSourceRootDisplayName), SRDescription(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.LocalPathToWebConfigUnderSourceRootDescription)]
        public string LocalPathToWebConfigUnderSourceRoot { get; set; }

        /// <summary>
        /// The name of the local file to be replaced with the transform file (for example, you might want to copy web.DEV.config onto web.Release.config).
        /// </summary>
        [Browsable(true), RefreshProperties(RefreshProperties.All), SRDisplayName(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.LocalFileNameToReplaceWithTransformFileDisplayName), SRDescription(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.LocalFileNameToReplaceWithTransformFileDescription)]
        public string LocalFileNameToReplaceWithTransformFile { get; set; }

        /// <summary>
        /// The path to the transform file under the transform root (e.g.: websites/MVCapp1/web.prod.config or services/MyService1/myservice1.exe.prod.config). 
        /// Note that this path is relative to the path specified in the "Configuration Files Path" setting under the "Configuration Settings -> Configuration File Settings" section.
        /// </summary>
        [Browsable(true), RefreshProperties(RefreshProperties.All), SRDisplayName(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.TransformFilePathForPrePackingingOverrideDisplayName), SRDescription(typeof(ExtendedWorkflowResources), ExtendedWorkflowResources.TransformFilePathForPrePackingingOverrideDescription)]
        public string TransformFilePathForPrePackingingOverride { get; set; }

        public override string ToString()
        {
            return string.Format("Local Path to Transform File (e.g. web.PROD.config) Relative to Source Root: {0} - Local File Name to Replace With Transform File: {1}",
                this.LocalPathToWebConfigUnderSourceRoot,
                this.LocalFileNameToReplaceWithTransformFile);
        }
    }
}
